package com.yl.ydk.ui.activity

import android.view.View
import androidx.recyclerview.widget.RecyclerView
import com.yl.ydk.R
import com.yl.ydk.base.BaseActivity
import com.yl.ydk.presenter.contract.TestPapersContract
import com.yl.ydk.presenter.impl.TestPapersImpl
import com.yl.ydk.utils.CommontUtils
import com.blankj.utilcode.utils.ToastUtils
import com.scwang.smart.refresh.footer.ClassicsFooter
import com.scwang.smart.refresh.header.ClassicsHeader
import com.scwang.smart.refresh.layout.SmartRefreshLayout
import kotlinx.android.synthetic.main.activity_test_papers.*
import kotlinx.android.synthetic.main.roob_bar.*


class TestPapersActivity : BaseActivity(), TestPapersContract.View, View.OnClickListener {

    private val mPresenter = TestPapersImpl()
    private var page = 1


    override fun getLayoutId(): Int = R.layout.activity_test_papers

    override fun attachView() {
        mPresenter.attachView(this)
    }

    override fun detachView() {
        mPresenter.detachView()
    }

    override fun initView() {
        rlBack.setOnClickListener(this)
        val query = intent.getStringExtra("data")
        val type = intent.getIntExtra("type", 1)
        tvName.text = query
        mPresenter.getTestPapers(this, CommontUtils.getPrama(type, page),false)
        val header = ClassicsHeader(this)
        header.setAccentColor(resources.getColor(R.color.white) )//设置强调颜色
        val footer = ClassicsFooter(this)
        footer.setAccentColor(resources.getColor(R.color.white) )
        refreshLayout.setRefreshHeader(header)
        refreshLayout.setRefreshFooter(footer)
        refreshLayout.setOnRefreshListener {
            page=1
            mPresenter.getTestPapers(this, CommontUtils.getPrama(type, page),false)
        }
        refreshLayout.setOnLoadMoreListener {
            page++
            mPresenter.getTestPapers(this, CommontUtils.getPrama(type, page),true)
        }
    }

    override fun getRvTest(): RecyclerView = rvTest

    override fun showError(message: String?) {
        ToastUtils.showLongToastSafe(message)
    }

    override fun getSmartRefreshLayout(): SmartRefreshLayout = refreshLayout

    override fun getActivity(): TestPapersActivity = this

    override fun onClick(v: View?) {
        when (v?.id) {
            R.id.rlBack -> {
                finish()
            }
        }
    }

}